<%! from mtp.lib.permissions import has_perm %>
<div class="comment_list">

<%def name="renderComment(comment)">
    <div class="comment">
        <div class="comment_info">
            From ${comment.user.username if comment.user else 'anon'} 
            at ${h.formatdatetime(comment.created)}
            % if comment.updated:
                ( edited ${h.formatdatetime(comment.updated)} )
            % endif
        </div>
        <div class="comment_body">${comment.body}</div>
        <div class="comment_options">
            <ul>
                % if has_perm('comment', 'create'):
                    <li><a href="${h.url_for('page_new_comment', page_id=c.page.urlTitle(), reply_to=comment.id)}" class="add_comment">Reply</a></li>
                % endif
                % if has_perm('comment', 'delete') or (c.user == comment.user):
                    <li><a href="${h.url_for('page_comment', page_id=c.page.urlTitle(), id=comment.id, _method='DELETE')}" class="delete_comment">Delete</a></li>
                % endif
                % if has_perm('comment', 'edit') or (c.user == comment.user):
                    <li><a href="${h.url_for('page_edit_comment', page_id=c.page.urlTitle(), id=comment.id)}" class="add_comment">Edit</a></li>
                % endif
            </ul>
        </div>

        % for child in comment.children:
            ${renderComment(child)}
        % endfor
    </div>
</%def>

<h1>Comments</h1>
% for comment in c.comments:
    ${renderComment(comment)}
% endfor
</div>

